﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using UML2DOC.Controller;
using UML2DOC.Controller.Commands;
using UML2DOC.Interfaces;
using UML2DOC.Adapters;

namespace UML2DOC
{
    public partial class MainWindow : Window
    {
        private ControllerMain controller;

        public MainWindow()
        {
            InitializeComponent();
            controller = new ControllerMain();

            controller.ClearSolutionFileInfoEvent += new ControllerMain.ClearSolutionFileInfo(controller_ClearSolutionFileInfoEvent);
            controller.UpdateSolutionFileInfoEvent += new ControllerMain.UpdateSolutionFileInfo(controller_UpdateSolutionFileInfoEvent);
            CommandGetSolutionFile cmdGetSolutionfile = new CommandGetSolutionFile(controller.GetSolutionFile);
            AdapaterGetSolutionFileName adapaterGetSolutionFileName = new AdapaterGetSolutionFileName(solutionselectionbutton, cmdGetSolutionfile);

            controller.ClearModelProjectsEvent += new ControllerMain.ClearModelProjects(controller_ClearModelProjectsInfoEvent);
            controller.LoadModelProjectsEvent += new ControllerMain.LoadModelProjects(controller_LoadModelProjectsEvent);
            
            controller.ClearDiagramsInfoEvent += new ControllerMain.ClearDiagrams(controller_ClearDiagramsInfoEvent);
            controller.LoadDiagramsInfoEvent += new ControllerMain.LoadDiagrams(controller_LoadDiagramsInfoEvent);
            CommandGetSelection cmdLoadDiagrams = new CommandGetSelection(controller.GetDiagrams);
            AdapaterGetDiagrams adapterGetDiagrams = new AdapaterGetDiagrams(ModelProjectSelection, cmdLoadDiagrams);
 
            CommandCreateDoc cmdCreateDoc = new CommandCreateDoc(controller.CreateUMLDocumenation);
            AdapterCreateDoc adapterCreateDoc = new AdapterCreateDoc(CreateButton, cmdCreateDoc, DiagramsList);
            //add event when ready creating
        }

        void controller_LoadDiagramsInfoEvent(IList<IDiagram> diagrams)
        {
            DiagramsList.ItemsSource = diagrams;

        }

        void controller_ClearDiagramsInfoEvent()
        {
            DiagramsList.Items.Clear();
        }

        private void mouse_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }

        private void ButtonTemplate_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
        }

        private void ButtonCreate_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            // TODO: Add event handler implementation here.
        }

        void controller_LoadModelProjectsEvent(ISolution solution)
        {
            ModelProjectSelection.ItemsSource = solution.ModelProjects;
            ModelProjectSelection.SelectedIndex = 0;
        }

        void controller_ClearModelProjectsInfoEvent()
        {
            ModelProjectSelection.Items.Clear();
        }

        void controller_UpdateSolutionFileInfoEvent(ISolution solution)
        {
            solutionfilename.Text = solution.Name;
        }

        void controller_ClearSolutionFileInfoEvent()
        {
            solutionfilename.Text = string.Empty;
        }


  

        private void Rectangle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            this.Window.DragMove();
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Window.Close();
        }		
    }
}
